#include "sqliteexpdialog.h"

SqliteExpDialog::SqliteExpDialog()
{
f = QLatin1String("");
setupUi(this);

fLineEdit->setText(f);
connect( fButton,
         SIGNAL( clicked() ),
         this,
         SLOT( select_file() ) );
}

SqliteExpDialog::~SqliteExpDialog()
{
}

QMap<QString, QVariant> SqliteExpDialog::return_data()
{
QMap<QString, QVariant> m;
m["file"] = QVariant( QDir::toNativeSeparators(f) );
    if ( true == fullRadioButton->isChecked() )
    {
    m["type"] = QVariant( QString( QLatin1String("FULL" ) ) );
    }
    else if ( true == mobileRadioButton->isChecked() )
    {
    m["type"] = QVariant( QString( QLatin1String("MOBILE" ) ) );
    }
    else
    {
    m["type"] = QVariant();
    }

return m;
}

void SqliteExpDialog::select_file()
{
f = QFileDialog::getSaveFileName( this,
                                  tr("Select File"),
                                  set_file_name(),
                                  tr("SQLITE DB (*.db);;All Files (*)") );
fLineEdit->setText(f);                                  
}

QString SqliteExpDialog::set_file_name()
{
QDate ldate = QDate::currentDate();
QString path;
QString home_path = QDir::homePath();
QString desktop_path = home_path;
desktop_path.append( QDir::separator() );
desktop_path.append( QLatin1String("Desktop") );
QDir desktop_dir(desktop_path);
    if ( true == desktop_dir.exists() )
    {
    path = desktop_path;
    }
    else
    {
    path = home_path;
    }
path.append( QDir::separator() );
path.append( QLatin1String("sqlite_") );
path.append( ldate.toString("yyyyMMdd") );
path.append( QLatin1String(".db") );
return QDir::toNativeSeparators(path);
}
